package com.xu.commons.dao.mpl;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.List;

import com.xu.commons.dao.BaseDao;
import com.xu.commons.dao.Database;

public class BaseDaoImpl<T,ID extends Serializable> implements BaseDao<T,ID>{
	  private Class pClass;

	    public BaseDaoImpl() {
	        //第一步，得到当前运行类的class
	        Class clazz = this.getClass();
	        //第二步，得到运行类的父类的参数化类型
	        Type type = clazz.getGenericSuperclass();
	        ParameterizedType pType=(ParameterizedType) type;
	        //第三步，得到实际类型参数
	        Type[] types = pType.getActualTypeArguments();
	        Class tClass= (Class) types[0];
	        this.pClass=tClass;
	    }
	@Override
	public List<T> findAll() {
		String sql="select * from "+pClass.getSimpleName().toLowerCase();
		return Database.queryEntityList(pClass, sql);
	}

	@Override
	public int insert(T t) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public T get(ID id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int update(T t) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int deleteById(Collection<ID> idList) {
		// TODO Auto-generated method stub
		return 0;
	}

}
